<?php
class Register extends Module{
	function Register($row)
	{
		Module::Module($row);

		switch(Url::get('cmd'))
		{
			case 'create_image':
				require_once 'forms/create_image.php';
				break;
			case 'check_account':
				$this->check_account();
				exit();
			case 'check_email':
				$this->check_email();
				exit();
			case 'check_security_code':
				$this->check_security_code();
				exit();
			case 'check_email_format':
				$this->check_email_format();
				exit();
			default:
				if(!User::is_login())
				{
					require_once 'forms/Register.php';
					$this->add_form(new RegisterForm);
				}
				else
				{
					Url::redirect();
				}
				break;
		}
	}
	
	function check_account()
	{
		if(Url::get('account_id') and DB::fetch('select * from account where user_email="'.Url::get('account_id').'"')){
			echo 'F';
			return true;	
		}
			
		echo 'T';
		
		return false;
	}
	
	function check_security_code()
	{
		if(Url::get('sercurity_code') and Url::get('sercurity_code') != $_SESSION['security_code']){
			echo 'T';
		}
		else{
			echo 'F';
		}
	}
	
	function check_email()
	{
		$email_type = 	new EmailType(true,'invalid_email');
		
		$email		=	Url::get('email');
		
		if($email && preg_match("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$",$email))
		{
			//echo 'Format-T';
			if(DB::fetch('select id,user_name,email from account where email="'.addslashes($email).'"')){
				echo 'Exist-T';
			}
			else{
				echo 'Exist-F';
			}
		}
		else{
			echo 'Format-F';			
		}
	}
}
?>